<script type="text/javascript" src="<?php echo base_url(); ?>/js/basic.js"></script>
<div id="content" class="testd"><br><br>
    <h1><?php if ($title) {
    echo $title;
} ?></h1><br>

    <script>

        var Timer;
        var TotalSeconds;


        function CreateTimer(TimerID, Time) {
            Timer = document.getElementById(TimerID);
            TotalSeconds = Time;

            UpdateTimer()
            window.setTimeout("Tick()", 1000);
        }

        function Tick() {
            if (TotalSeconds <= 0) {
                alert("Time's up!")
                return;
            }

            TotalSeconds -= 1;
            UpdateTimer()
            window.setTimeout("Tick()", 1000);
        }

        function UpdateTimer() {
            var Seconds = TotalSeconds;

            var Days = Math.floor(Seconds / 86400);
            Seconds -= Days * 86400;

            var Hours = Math.floor(Seconds / 3600);
            Seconds -= Hours * (3600);

            var Minutes = Math.floor(Seconds / 60);
            Seconds -= Minutes * (60);


            var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)


            Timer.innerHTML = TimeStr;
        }


        function LeadingZero(Time) {

            return (Time < 10) ? "0" + Time : +Time;

        }

        //var myCountdown1 = new Countdown({time:<?php echo $seconds; ?>, rangeHi:"hour", rangeLo:"second"});
        setTimeout(submitform, '<?php echo $seconds * 1000; ?>');
        function submitform() {
            alert('Time Over');
            document.getElementById('testform').submit();
        }

        setInterval(setqtime, 1000);

        function setqtime() {

            qtime += 1;
        }

        $(document).ready(function() {
            hideqnobycate();
        });


    </script>
    <div class="wite">

        <div style="float:left; font-size:13px;">

            Time left: <div id='timer' style="display:inline;"/>
            <script type="text/javascript">window.onload = CreateTimer("timer", <?php echo $seconds; ?>);</script>
        </div>
    </div>
    <div style="clear:both;"></div>

    <div  id="left_div">
        <?php
        $category_name = explode(",", $time_info['category_name']);
        $cate_range = array();
        $startnextcate = array();
        $qids_range = explode(",", $time_info['qids_range']);
        foreach ($qids_range as $key => $rangeval) {
            $rangeval_arr = explode("-", $rangeval);
            $gen_range = array();
            $startnextcate[] = $rangeval_arr['1'];
            for ($x = $rangeval_arr['0']; $x <= $rangeval_arr['1']; $x++) {
                $gen_range[] = $x;
            }
            $cate_range[] = $gen_range;
        }
        ?>
        <input type="hidden"  id="json_category_range" value='<?php echo json_encode($cate_range); ?>'>
        <?php
        foreach ($category_name as $key => $cvalue) {
            ?>
            <?php if ($key == '0') { ?>
                <input type="hidden" value="0" id="current_cate">
                <?php
            }
            ?>
            <div class="category_box" id="cate-<?php echo $key; ?>" <?php if ($key == "0") {
                echo "style='background:#2f72b7;color:#ffffff;'";
            } ?> onClick="changecategory('<?php echo $key; ?>');"><?php echo $cvalue; ?></div>

    <?php
}
?>
        <input type="hidden" value="<?php echo $key; ?>" id="total_cate">

        <div style="clear:both;"></div>

        <form action="<?php echo site_url('quiz/submit_quiz/' . $quiz_id); ?>" method="post" id="testform" onsubmit="showquestion('0');">
            <?php
            $category_number = 0;

            $selected_oids = explode(",", $time_info['oids']);
            foreach ($assigned_question[0] as $key => $question) {
                ?>
                <?php if ($key == '0') { ?>
                    <input type="hidden" value="0" id="current_question">
                    <?php
                }
                ?>
                <table id="ques<?php echo $key; ?>" class="<?php if ($key == '0') {
                    echo 'showquestion';
                } else {
                    echo 'hidequestion';
                } ?>">
                    <tr><td >Question <?php echo $key + 1; ?></td></tr>
                    <tr><td> <?php echo $question['question']; ?></td></tr>
    <?php
    $opcount = 0;
    foreach ($assigned_question[1] as $keys => $option) {
        if ($option['qid'] == $question['qid']) {
            ?>
                            <tr><td><table>
                                        <tr><td style="width:10px; border:0px;"> <input type="radio"  id="op-<?php echo $key; ?>-<?php echo $opcount; ?>" name="answers<?php echo $key; ?>" value="<?php echo $option['oid']; ?>" onClick="update_answer(this.value);
                                                answered_color();" <?php if ($selected_oids[$key] == $option['oid']) {
                    echo "checked";
                } ?> > </td>
                                            <td style="border:0px;width:750px;"> <?php echo $option['option_value']; ?></td></tr></table>
                                </td></tr>
                                    <?php
                                    $opcount+=1;
                                }
                            }
                            ?>
                    <tr><td> 
                            <?php
                            if ($key >= "1") {
                                ?>
                                <input type="button" value="Back"  onClick="showquestion('<?php echo $key - 1; ?>');">
                                <?php
                            }

                            if ($key != (count($assigned_question['0']) - 1)) {
                                if (in_array($key, $startnextcate)) {
                                    $category_number+=1;
                                    ?>
                                    <input type="button" value="Next"  onClick="showquestion('<?php echo $key + 1; ?>');
                                            changecategory('<?php echo $category_number; ?>')">
            <?php
        } else {
            ?>
                                    <input type="button" value="Next"  onClick="showquestion('<?php echo $key + 1; ?>');">
            <?php
        }
    }
    ?>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="checkbox" value="1" onClick="reviewlater();"> Tick to review later
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="button" onClick="clearresponse('<?php echo $key; ?>');" value="Clear Response">
                        </td></tr>

                </table>

    <?php
}
?>

            <table id="detail">
                <tr><td ><input type="hidden" name="noq" id="noq" value="<?php echo $key; ?>"><input type="submit" value="Submit Quiz"></td></tr>
            </table>
        </form>
    </div>
    <div id="left_div" style="padding:10px;">
        Questions<br>
<?php
foreach ($assigned_question[0] as $key => $question) {
    ?>
            <div class="count_btn" id="nq<?php echo $key; ?>" onClick="showquestion('<?php echo $key; ?>');"><?php echo $key + 1; ?></div>
    <?php
}
?>
    </div>
    <div style="clear:both"></div>
</div>
<br><br>
<table>
    <tr><td><div class="count_btn" style="background:#267B02;">&nbsp;</div> Answered</td></tr>
    <tr><td><div class="count_btn" style="background:#D03800;">&nbsp;</div> UnAnswered</td></tr>
    <tr><td><div class="count_btn" style="background:#FFD800;">&nbsp;</div> Review Later</td></tr>
</table>
Note: Do not refresh page.
<br><hr>


</div>


